package com.ycy.create;

import com.ycy.BaseTest;
import org.flowable.engine.*;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.engine.repository.Deployment;
import org.junit.Before;
import org.junit.Test;

public class H2CreateDemo {

  protected ProcessEngine processEngine;

  protected ProcessEngineConfiguration cfg;

  // 获取Flowable服务 Get Flowable repositoryService
  protected RepositoryService repositoryService;

  // 获取Flowable服务 Get Flowable runtimeService
  protected RuntimeService runtimeService;

  // 获取taskService对象 Get the first task
  protected TaskService taskService;

  protected HistoryService historyService;

  @Before
  public void create() {
    ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
            .setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
            .setJdbcUsername("sa")
            .setJdbcPassword("")
            .setJdbcDriver("org.h2.Driver")
            .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    this.cfg = cfg;
    ProcessEngine processEngine = cfg.buildProcessEngine();
  }

  @Test
  public void creat0() {
    // 创建Flowable流程引擎 Create Flowable process engine
    ProcessEngine processEngine = cfg.buildProcessEngine();
    // 获取Flowable服务 Get Flowable repositoryService
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deploy = repositoryService.createDeployment().addClasspathResource("diagram/easy_key.bpmn20.xml").deploy();
    System.out.println(deploy.getId());
  }

}
